<?php

require_once '../config.php';
require_once '../functions.php';



$common = empty($_GET['common']) ? 1: (int)$_GET['common'];
$con_number = book_fetch_one("select 
count(1)
from comm
inner join list on list.list_isbn=comm.comm_isbn");
if((int)$common < 1){
    header('Location: /admin/common.php?common=1');
}


// 基本信息
$comm = book_fetch_all("select 
comm.name,
list.id,
list.title,
list.picture,
list.number,
comm.publisher,
comm.pages,
comm.price,
comm.pad,
comm.com_data,
comm.produce,
comm.comm_isbn
from comm
inner join list on list.list_isbn=comm.comm_isbn
where list.id={$common}
");



// 内容
$option = book_fetch_all("select 
list.id,
options.description,
options.authors,
options.link,
options.discussnum
from options
inner join list on list.list_isbn=options.option_isbn
where list.id={$common}");

$row = book_execute("update list set number=number+1 where list.id={$common}");


// 评论
$make = book_fetch_all("select 
make.name,
make.make_content,
make.make_data,
list.list_isbn
from make 
inner join list on list.list_isbn = make.make_isbn
where list.id={$common}
");


function list_date ($created) {
    // => '2017-07-01 08:08:00'
    // 如果配置文件没有配置时区
    // date_default_timezone_set('PRC');
    $timestamp = strtotime($created);
    return date('Y年m月d日', $timestamp);
  }


$current_user=books_get_current_user();

global $isbn;
    $isbn=$comm[0]['comm_isbn'];


function common (){

    if(empty($_POST['name'])){
        $GLOBALS['message']='潇洒地写出你的名字';
        return;
    }
    if(empty($_POST['nick_name'])){
        $GLOBALS['message']='潇洒地写出你的名字';
        return;
    }
    
    if(empty($_POST['qq'])){
        $GLOBALS['message']='潇洒地写出你的名字';
        return;
    }
    if(empty($_POST['text'])){
        $GLOBALS['message']='潇洒地写出你的名字';
        return;
    }
    $day=date("Y/m/d h:m:s");
    $name = $_POST['name'];
    $nick_name = $_POST['nick_name'];
    $qq = $_POST['qq'];
    $text = $_POST['text'];
    $isbns = $GLOBALS['isbn'];
 
    

    $row = book_execute("insert into make (id,name,make_qq,make_nick,make_content,make_data,make_isbn) values(null,'$name','$qq','$nick_name','$text','$day','$isbns')");

    


}
if($_SERVER['REQUEST_METHOD'] ==='POST'){
    common();
    $make = book_fetch_all("select 
make.name,
make.make_content,
make.make_data,
list.list_isbn
from make 
inner join list on list.list_isbn = make.make_isbn
where list.id={$common}
");
}




?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Common  &laquo; Admin</title>
    <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/assets/css/base.css">
    <link rel="stylesheet" href="/static/assets/css/index.css">
    <link rel="stylesheet" href="/static/assets/css/common.css">
    <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
    <script src="/static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<style>
</style>

<body>

<script>NProgress.start()</script>

    <!-- 导航栏 -->
    <?php include 'inc/navbar.php'; ?>
    
    <div class="bs_common">
        <div class="bs_common_head">
        <?php foreach($comm as $item):?>
            <div class="head_left">
                <a href="<?php echo $item['picture']?>" id="picd">
                    <img src="<?php echo $item['picture']?>" alt="" id="pica">
                </a>
            </div>
            <div class="head_right">
                <h1><?php echo $item['title']?></h1>
                <p> 作者: <?php echo $item['name']?></p>
                <p>出版社: <?php echo $item['publisher']?></p>
                <p>页数<?php echo $item['pages']?></p>
                <p>价格<?php echo $item['price']?></p>
                <p>出品方: <?php echo $item['produce']?></p>
                <p>出版年: 2020-2-10</p>
                <p>装帧: <?php echo $item['pad']?></p>
                <p>ISBN: <?php echo $item['comm_isbn']?></p>
            </div>
            <?php endforeach?>
        </div>
        <?php foreach($option as $item):?>
        <div class="bs_common_author">
            <h4>作者简介</h4>
            <p><?php echo $item['authors']?></p>
        </div>
        <div class="bs_common_content">
            <h4>内容</h4>
            <p> <?php echo $item['description']?></p>
            <a href="<?php echo $item['link']?>">试读</a>
        </div>
        <?php endforeach?>
        <form action="<?php $_SERVER['PHP_SELF']?>" method="post">
            <div class="bs_common_remark">
                <h4>发表评论</h4>
                <textarea class="text1" name="text" id="text" cols="115" rows="7" placeholder="来啊，看过来"></textarea>
                <div class="pinglun">
                    <div class="pinglun_name">
                        <label for="name" class="pl">姓名</label><br>
                        <input type="text" name="name" id="name" class="from-control text" placeholder="姓名">
                    </div>
                    <div class="pinglun_nick">
                        <label form="nick_name" class="pl">昵称</label><br>
                        <input type="text" name="nick_name" id="nick_name" class="from-control text" placeholder="昵称">
                    </div>
                    <div class="pinglun_qq">
                        <label form="email" class="pl">邮箱</label><br>
                        <input type="email" name="qq" id="qq" class="from-control text" placeholder="QQ邮箱">
                    </div>
                </div>
                <button class="btn">发表评论</button>
            </div>
        </form>
        <div class="pinglun_list">
            <ul style="list-style: none;">
            <?php foreach($make as $item):?>    
                  <li>
                    <h3>时间：<?php echo list_date($item['make_data']) ?></h3>
                    <p><?php echo $item['make_content']?></p>
                    <p>———— <?php echo $item['name']?></p> 
                </li>
                <?php endforeach?>
                

                
            </ul>
        </div>
        <div class="intellectual_property">
                <p>© 2018-2020 Copyright | 粤ICP备18151546号 </p>
        </div>
       
    </div>

    <script src="/static/assets/vendors/jquery/jquery.min.js"></script>
    <script src="/static/assets/vendors/bootstrap/js/bootstrap.js"></script>
    <script src="/static/assets/vendors/jsrender/jsrender.js"></script>

    <script>
        $('.collapse').collapse();
        // 小图切换大图
        $('pica').onclick = function () {
            this.src = $('picd').src
            return false;
        }       
    </script>
    <script>NProgress.done()</script>
</body>

</html>